package movieGandalf.dataObjects;

import java.math.BigInteger;
import java.sql.Connection;
import java.util.List;

import movieGandalf.database.MovieTools;
import movieGandalf.logicGuiConnection.Movie;
import movieGandalf.logicGuiConnection.User;

public class UserImp implements User{
      
	private BigInteger userID;
	private String username;
	private String password;
	private Boolean isAdmin;
	
	// Constructor
	
	public UserImp(BigInteger userID, String username, String password, Boolean isAdmin){
		this.userID = userID;
		this.username = username;
		this.password = password;
		this.isAdmin = isAdmin;
	}
	
	//Getters
	
	public BigInteger getID(){
		return userID;
	}
	
	public String getUsername(){
		return username;
	}
    
    public String getPassword(){
    	return password;
    }
    
    public boolean isPassword(String password){
    	return this.password.equals(password);
    }
    
    public Boolean isAdmin(){
    	return isAdmin;
    }
    
    public List<Movie> getWishList(){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getWishList(conn,this.getID());
    }
    
    public List<Movie> getAlreadySeenList(){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getAlreadySeen(conn,this.getID());
    }
    
    public List<Movie> getMustSeeList(){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		return MovieTools.getMustSee(conn,this.getID());
    }

    // Setters
    
	public void setUserID(BigInteger id) {
		this.userID = id;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
		
	}

	public void setAdmin(Boolean isAdmin) {
		this.isAdmin = isAdmin;
	}
	
	// List changers
	
	public boolean addWishList(BigInteger movieID){
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.addWishList(conn,this.getID(),movieID);
	}
    
    public boolean addAlreadySeenList(BigInteger movieID){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.addAlreadySeen(conn,this.getID(),movieID);
    }
    
    public boolean addMustSeeList(BigInteger movieID){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.addMustSee(conn,this.getID(),movieID);
    }
    
    public boolean removeWishList(BigInteger movieID){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteWishList(conn,this.getID(),movieID);
    }
    
    public boolean removeAlreadySeenList(BigInteger movieID){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteAlreadySeen(conn,this.getID(),movieID);
    }
    
    public boolean removeMustSeeList(BigInteger movieID){
    	Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteMustSee(conn,this.getID(),movieID);
    }
	
    
    //update and delete

	public boolean update() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.updateUser(conn, this);
	}
	
	public boolean delete() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteObject(conn,this);
	}

}